﻿using ApiDAL.Common;
using DataAccess.SqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using System.Data.SqlClient;

namespace Dal
{
    public class CarDAL
    {
        #region 显示购物车
        public List<Car> SelCar(int UserID)
        {         
            SqlQuery sql = new SqlQuery();
            sql.CommandText = "CarShow";
            sql.CommandType = CommandType.StoredProcedure;

            SqlParameter sql1 = new SqlParameter();
            sql1.Value = UserID;
            sql1.ParameterName = "@UserID";
            sql.Parameters.Add(sql1);
            DataSet ds = SqlDataAccess.ExecDataset(sql);
            DataTable dt1 = ds.Tables[0];
            return DataReaderToObjectHelper.DataTableToList<Car>(dt1);
        }
        #endregion

        #region 添加购物车
        public int InsertOrder(int id)
        {
            SqlQuery sql = new SqlQuery();
            sql.CommandText = "Proc_InsertCar";
            sql.CommandType = CommandType.StoredProcedure;

            SqlParameter sql1 = new SqlParameter();
            sql1.Value = id;
            sql1.ParameterName = "@id";
            sql.Parameters.Add(sql1);
            int i = SqlDataAccess.ExecNonQuery(sql);
            return i;
        }
        #endregion

        #region 删除购物车
        public int DelCar(int CarId)
        {
            SqlQuery sql = new SqlQuery();
            sql.CommandText = "Proc_Del";
            sql.CommandType = CommandType.StoredProcedure;

            SqlParameter sql1 = new SqlParameter();
            sql1.Value = CarId;
            sql1.ParameterName = "@CarId";
            sql.Parameters.Add(sql1);

            int i = SqlDataAccess.ExecNonQuery(sql);
            return i;
        }
        #endregion

        #region 数量添加
        public int AddUpdate(int CarId)
        {
            SqlQuery sql = new SqlQuery();
            sql.CommandText = "Proc_AddUpdate";
            sql.CommandType = CommandType.StoredProcedure;

            SqlParameter sql1 = new SqlParameter();
            sql1.Value = CarId;
            sql1.ParameterName = "@CarId";
            sql.Parameters.Add(sql1);

            int i = SqlDataAccess.ExecNonQuery(sql);
            return i;
        }
        #endregion

        #region 数量修改
        public int JianUpdate(int CarId)
        {
            SqlQuery sql = new SqlQuery();
            sql.CommandText = "Proc_JianUpdate";
            sql.CommandType = CommandType.StoredProcedure;

            SqlParameter sql1 = new SqlParameter();
            sql1.Value = CarId;
            sql1.ParameterName = "@CarId";
            sql.Parameters.Add(sql1);

            int i = SqlDataAccess.ExecNonQuery(sql);
            return i;
        }

        #endregion
    }
}
